package com.seuic.hnjiningposapp.hnapps.ui.view.dialog;

import android.content.Context;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;

import java.text.DecimalFormat;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 输入圈存信息
 */
public class InputSaveInfoPp extends BasePopupView {
    @BindView(R.id.input_money_title)
    TextView inputMoneyTitle;
    @BindView(R.id.sure_remittance_num)
    TextView sureRemittanceNum;
    @BindView(R.id.sure_user_name)
    TextView sureUserName;
    @BindView(R.id.sure_balance)
    TextView sureBalance;
    @BindView(R.id.input_money_edtext)
    EditText inputMoneyEdtext;
    Unbinder bind;
    @BindView(R.id.next_btn)
    Button nextBtn;
    SureInputSaveCallBack mSureInputSaveCallBack;

    public InputSaveInfoPp(@NonNull Context context, SureInputSaveCallBack sureInputSaveCallBack) {
        super(context);
        this.mSureInputSaveCallBack = sureInputSaveCallBack;
    }

    @Override
    protected int getPopupLayoutId() {
        return R.layout.input_saveinfo_pplayout;
    }

    String mCardNum;
    String mUserName;
    String mBalance;

    public void setmCardNum(String mCardNum) {
        this.mCardNum = mCardNum;
    }

    public void setmUserName(String mUserName) {
        this.mUserName = mUserName;
    }

    public void setmBalance(String mBalance) {
        this.mBalance = mBalance;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        bind = ButterKnife.bind(this);
        sureRemittanceNum.setText(mCardNum);//卡号
        sureUserName.setText(mUserName);//用户名
        sureBalance.setText(mBalance);//电子现金余额

    }

    @OnClick(R.id.next_btn)
    public void onViewClicked() {
        if (inputMoneyEdtext.getText().toString().equals("")) {
            ToastUtils.showLong("请输入圈存金额");
            return;
        }
        Double mm;
        DecimalFormat myformat = new DecimalFormat("#0.00");
        mm = Double.parseDouble(inputMoneyEdtext.getText().toString());//装换为double类型
        mm = Double.parseDouble(myformat.format(mm));//保留小数
        if (mm > 1000) {
            ToastUtils.showLong("圈存金额不能大于1000");
            return;
        }
        mSureInputSaveCallBack.SureInputSaveCallBack(inputMoneyEdtext.getText().toString());
    }

    public interface SureInputSaveCallBack {
        void SureInputSaveCallBack(String money);
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
        //注解解绑
        if (bind != null && bind != Unbinder.EMPTY) {
            bind.unbind();
        }
        this.bind = null;
    }

}
